package com.ibiaoke.common.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 随机数工具
 */
public class RandomUtils {

    public static int[] nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    public static Random random = new Random();

    /**
     * 生成随机数字
     *
     * @param length 随机数长度
     * @return
     */
    public static String randomNumber(int length) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(10);
            builder.append(nums[index]);
        }
        return builder.toString();
    }

    public static OrderNoGenerator generator=new OrderNoGenerator(100,3);

    public static  String generatorOrderNo() {
        return generator.generatorOrderNo();
    }

    public static void main(String[] args) {

        for (int j = 0; j < 100000000; j++) {
            int count = 0;
            Map<String, String> map = new HashMap<>();
            for (int i = 0; i < 100; i++) {
                String randomNumber = generatorOrderNo();
                if (map.get(randomNumber) != null) {
                    count++;
                    System.out.println("订单号重复" + count + "次");
                }
                map.put(randomNumber, randomNumber);
            }
        }
    }
}
